<% layout('/layout/default.html', {title: '机构管理', libs: ['layui']}){ %>
<div class="main-content">
		<div class="card-header">
			<i class="fa fa-sitemap"></i> 机构管理
			<div class="header-tools float-right">
				<a href="#" class="btn btn-default btn-sm"  id="btnRefreshTree" title="刷新"><i class="fa fa-refresh"></i> 刷新</a>
				<a href="#" class="btn btn-default btn-sm" id="btnExpandTreeNode" title="展开全部"><i class="fa fa-angle-double-down"></i> 展开</a>
				<a href="#" class="btn btn-default btn-sm" id="btnCollapseTreeNode" title="折叠全部"><i class="fa fa-angle-double-up"></i> 折叠</a>
				<% if(hasPermi('sys:office:edit')){ %>
					<a href="/sys/office/form" class="btn btn-default btn-sm btnTool" title="添加机构"><i class="fa fa-plus"></i> 添加机构</a>
				<% } %>
			</div>
		</div>
		<div class="container-fluid">
			<form id="searchForm" action="${ctx}/sys/office/listData" class="form-inline d-none">
				<div class="form-group">
					<button type="submit" class="btn btn-success btn-sm ">查询</button>
					<button type="reset" class="btn btn-default btn-sm">重置</button>
				</div>
			</form>			
			<table id="btGrid"></table>
		</div>
</div>
<% } %>
<script>
//初始化layui-table对象
$('#btGrid').BTGrid({
	searchForm: $("#searchForm"),
	treeEnable:true,
	columnModel: [
		{title:'机构名称', field:'name'},
		{title:'归属区域', field:'areaName'},
		{title:'机构编码', field:'code'},
		{title:'机构类型', templet:function(row) {
				return js.transDictLabel(${@DictUtils.getDictListJson('sys_office_type')}, row.type, '');
			}},
		{title:'备注', field:'remarks'},
		{title:'操作', templet:function(row){
				var actions = [];
				<% if(hasPermi('sys:office:edit')){ %>
					 actions.push('<a href="/sys/office/form?parentId='+row.id+'" lay-event="btnList" class="btn btn-xs btn-success btnList" title="添加下级机构"><i class="fa fa-plus-square"></i></a>&nbsp&nbsp');
					 actions.push('<a href="/sys/office/form?id='+row.id+'&area.id='+row.areaId+'" lay-event="btnList" class="btn btn-xs btn-primary btnList" title="修改机构信息"><i class="far fa-edit"></i></a>&nbsp&nbsp');
					 actions.push('<a href="${ctx}/sys/office/delete?id='+row.id+'" lay-event="btnList" class="btn btn-xs btn-danger btnList" title="删除机构" data-confirm="要删除该机构及所有子机构项吗？"><i class="far fa-trash-alt"></i></a>&nbsp&nbsp');
				<% } %>
				return actions.join('');
			}}
	],

	// 加载成功后执行事件
	ajaxSuccess: function(data){
		js.print(data);
	}
});
</script>